package t03;

import java.util.Comparator;

public class Employee implements Comparable<Employee> {
    private String name;
    private int age;
    private double salary;

    public Employee(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }


    public int getAge() {
        return age;
    }


    public double getSalary() {
        return salary;
    }


    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }


    // Comparable接口的方法
    @Override
    public int compareTo(Employee e) {
        // 由于程序设计，此处的getSalary()，如果换为salary，会导致比较错误
        return this.getSalary() < e.getSalary() ? -1 : this.getSalary() == e.getSalary() ? 0 : 1;
    }

}
